package com.shanzmoo.base.util;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import lombok.experimental.UtilityClass;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author fs
 * 集合工具类封装
 */
@UtilityClass
public class CollectionUtil extends CollUtil {

    /**
     * 转换
     *
     * @param list  源集合
     * @param clazz 新集合的元素类型
     * @param <T>
     * @return
     */
    public <T,E> List<T> convert(List<E> list, Class<T> clazz) {
        if (isNotEmpty(list)) {
            List<T> result = new ArrayList(list.size());
            for (Object bean : list) {
                result.add(BeanUtil.toBean(bean, clazz));
            }
            return result;
        } else {
            return Collections.emptyList();
        }
    }
}
